package net.larsan.dconf.cli;

import java.io.File;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Scanner;

import com.google.inject.Singleton;

@Singleton
public class SystemInputHandler implements InputHandler {

	@Override
	public LineReader getDefaultReader() {
		return new LineReader() {
			
			private Scanner scan = new Scanner(getDefaultInput());
			
			@Override
			public boolean hasNextLine() {
				return scan.hasNextLine();
			}
			
			@Override
			public String readLine() {
				return scan.nextLine();
			}
		};
	}

	@Override
	public InputStream getDefaultInput() {
		return System.in;
	}
	
	@Override
	public File newFile(String name) {
		return new File(name);
	}
	
	@Override
	public URL newURL(String name) throws MalformedURLException {
		return new URL(name);
	}
}
